@use './theme/base.scss' as *;

// 文本省略
@mixin text-ellipsis($lines: 1) {
  @if $lines == 1 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  } @else {
    display: -webkit-box;
    -webkit-line-clamp: $lines;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

// 多行文本溢出省略
@mixin text-ellipsis-multiple($lines: 2) {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: $lines;
  overflow: hidden;
}

// flex 布局
@mixin flex($direction: row, $justify: flex-start, $align: stretch, $gap: 0) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
  align-items: $align;
  flex-wrap: nowrap; // 默认不换行
  gap: $gap;
}

@mixin flex-center($gap: 0) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: $gap;
}

@mixin flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 响应式
@mixin respond-to($breakpoint) {
  @if $breakpoint == 'mobile' {
    @media screen and (max-width: $breakpoint-sm) {
      @content;
    }
  } @else if $breakpoint == 'tablet' {
    @media screen and (min-width: $breakpoint-sm) and (max-width: $breakpoint-md) {
      @content;
    }
  } @else if $breakpoint == 'desktop' {
    @media screen and (min-width: $breakpoint-md) {
      @content;
    }
  }
}

// 滚动条美化
@mixin scrollbar {
  &::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba($text-secondary, 0.3);
    border-radius: $radius-round;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }
}

// 卡片悬浮效果
@mixin hover-shadow {
  transition: $transition-base;
  &:hover {
    transform: translateY(-4px);
    box-shadow: $shadow-medium;
  }
}

// ... 其他通用 mixins

@mixin flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

// 自定义滚动条样式
@mixin custom-scrollbar {
  &::-webkit-scrollbar {
    width: 6px;
    height: 6px;
  }

  &::-webkit-scrollbar-thumb {
    border-radius: 3px;
    background-color: rgba($color-primary, 0.2);

    &:hover {
      background-color: rgba($color-primary, 0.3);
    }
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  // Firefox
  scrollbar-width: thin;
  scrollbar-color: rgba($color-primary, 0.2) transparent;
}

// 文本溢出省略
@mixin text-ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

// 渐变背景
@mixin gradient-bg($start-color, $end-color, $direction: 135deg) {
  background: linear-gradient($direction, $start-color, $end-color);
}

// 毛玻璃效果
@mixin glass-effect($bg-color: rgba(255, 255, 255, 0.8)) {
  background: $bg-color;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

// 阴影效果
@mixin box-shadow($level: 'base') {
  @if $level == 'light' {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  } @else if $level == 'base' {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  } @else if $level == 'medium' {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  } @else if $level == 'dark' {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
  }
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == 'sm' {
    @media screen and (max-width: $breakpoint-sm) {
      @content;
    }
  } @else if $breakpoint == 'md' {
    @media screen and (max-width: $breakpoint-md) {
      @content;
    }
  } @else if $breakpoint == 'lg' {
    @media screen and (max-width: $breakpoint-lg) {
      @content;
    }
  } @else if $breakpoint == 'xl' {
    @media screen and (max-width: $breakpoint-xl) {
      @content;
    }
  }
}

// 过渡动画
@mixin transition($properties: all, $duration: 0.3s, $timing: ease) {
  transition: $properties $duration $timing;
}

// grid 布局
@mixin grid($columns: 1fr, $gap: 16px) {
  display: grid;
  grid-template-columns: $columns;
  gap: $gap;
}
